<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>面向对象</title>
</head>
<body>
</body>


<script>
    // 类的定义和使用
    // 定义person类
    class person1 {
        constructor(name, age) {
            this.name = name;
            this.age = age;
        }

        show() {
            document.write(this.name + "," + this.age + "<br>")
        }

        eat() {
            document.write("吃饭...");
        }
    }

    let person = new person1("张三", 23);
    person.show();
    person.eat();

    // 继承
    class worker extends person1{
        constructor(name,age,sarlay){
            super(name,age);
            this.salary=sarlay;
    }
        work(){
            document.write("在工作")
        }
    }

    let worker1 = new worker("张三",23,10000);
    worker1.eat();



    // 字面类的定义和使用
    let person2 = {
        name: "张三",
        age: 23,
        hobby: ["听课", "学习"],
        eat: function () {
            document.write("吃饭")
        }
    };

    document.write(person2.name);
    person2.eat();;





</script>
</html>